<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            * {
                padding: 0;
                margin: 0;
                list-style: none;
            }
            html,
            body {
                width: 100%;
                height: 100%;
                border: 1px solid black;
                overflow: hidden;
                box-sizing: border-box;
            }
            body {
                display: flex;
                justify-content: center;
                align-items: center;
            }
            .login {
                width: 60%;
                height: 500px;
            }
            #user {
                width: 100%;
                height: 50px;
                border: 1px solid black;
                font-size: 23px;
            }
            #pwd {
                width: 100%;
                height: 50px;
                border: 1px solid black;
                font-size: 23px;
            }
            #newpwd {
                width: 100%;
                height: 50px;
                border: 1px solid black;
                font-size: 23px;
            }

            #btn {
                width: 65%;
                height: 30px;
                text-align: center;
                line-height: 30px;
                font-size: 25px;
            }
        </style>
    </head>
    <body>
        <div class="login">
            <input type="text" placeholder="请输入用户名" id="user" />
            <br />
            <br />
            <input type="password" placeholder="请输入密码" id="pwd" />
            <br />
            <br />
            <input type="password" placeholder="请确认密码" id="newpwd" />
            <br />
            <br />
            <button id="btn">注册</button>
        </div>
    </body>
    <script src="./axios.js"></script>
    <script>
        btn.onclick = () => {
            if (user.value == '' || pwd.value == '' || newpwd.value == '') {
                alert('清输入');
            } else {
                if (pwd.value == newpwd.value) {
                    axios
                        .post('/registry', {
                            user: user.value,
                            pwd: pwd.value,
                        })
                        .then(res => {
                            if (res.data.code == 1) {
                                alert(res.data.msg);
                                location.href = '/';
                            } else {
                                alert(res.data.msg);
                            }
                        });
                } else {
                    alert('俩次密码不一致');
                }
            }
        };
    </script>
</html>
